﻿using System.Text;

namespace Community.CsharpSqlite.Entity
{
    /*
    ** An objected used to accumulate the text of a string where we
    ** do not necessarily know how big the string will be in the end.
    */

    public struct StrAccum
    {
        public Mem Context;
        public sqlite3 db; /* Optional database for lookaside.  Can be NULL */
        public int mxAlloc; /* Maximum allowed string length */
        public int nAlloc; /* Amount of space allocated in zText */
        public int nChar; /* Length of the string so far */
        // Cannot happen under C#
        //public byte mallocFailed;   /* Becomes true if any memory allocation fails */
        public byte tooBig; /* Becomes true if string size exceeds limits */
        public byte useMalloc; /* True if zText is enlargeable using realloc */
        public StringBuilder zBase; /* A base allocation.  Not from malloc. */
        public StringBuilder zText; /* The string collected so far */

        public StrAccum(int n)
        {
            db = null;
            zBase = new StringBuilder(n);
            zText = new StringBuilder(n);
            nChar = 0;
            nAlloc = n;
            mxAlloc = 0;
            useMalloc = 0;
            tooBig = 0;
            Context = null;
        }
    };
}